import { Pagination } from "antd";
import { Link } from "react-router-dom";
import qs from "qs";
import { useLocation } from "react-router";

export default function IndexPagination() {
    let { search } = useLocation();
    let { tab = "all", page = 1 } = qs.parse(search.substr(1));
    return (
        <div>
            <Pagination
                className="index-pagination"
                defaultCurrent={page}
                total={1000}
                defaultPageSize={20}
                itemRender={(page, type) => {
                    switch (type) {
                        case "page":
                            return (
                                <Link to={`/?tab=${tab}&page=${page}`}>
                                    {page}
                                </Link>
                            );

                        case "prev":
                            return (
                                <Link to={`/?tab=${tab}&page=${page}`}>
                                    {"<"}
                                </Link>
                            );

                        case "next":
                            return (
                                <Link to={`/?tab=${tab}&page=${page}`}>
                                    {">"}
                                </Link>
                            );
                        default:
                            return (
                                <Link to={`/?tab=${tab}&page=${page}`}>
                                    {"......"}
                                </Link>
                            );
                    }
                    return page;
                }}
            />
        </div>
    );
}
